package cn.dz.domain.mp.controller;

import cn.dz.domain.mp.mapper.UserMapper;
import cn.dz.domain.mp.po.User;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserController
 * @package: cn.dz.domain.mp.controller
 * @Description UserController访问控制类
 * @Author dz
 * @Date 2025/1/9 11:18
 * @Version 1.0
 **/
@RestController
public class UserController {

    private UserMapper userMapper;
    @Autowired
    public UserController(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @GetMapping("/user")
    public String getUser() {
        User user = new User();
        user.setUsername("张三");
        user = userMapper.queryById(1);
        System.out.println(user);
        return user.toString();
    }

    @GetMapping("/user2")
    public String getUserByUsername() {
        // 创建 QueryWrapper 对象
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        // 设置查询条件
        queryWrapper.eq("username", "Jack");
        // 调用 selectOne 方法查询单条记录
        // 使用 QueryWrapper 进行查询
        User user = userMapper.selectOne(queryWrapper);
        return user.toString();
    }
}
